package com.ruoyi.web.controller.hos;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hos.domain.Bed;
import com.ruoyi.hos.service.IBedService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病床Controller
 *
 * @author bed
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/system/bed")
public class BedController extends BaseController
{
    @Autowired
    private IBedService bedService;

    /**
     * 查询病床列表
     */
    @PreAuthorize("@ss.hasPermi('system:bed:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bed bed)
    {
        startPage();
        List<Bed> list = bedService.selectBedList(bed);
        return getDataTable(list);
    }

    /**
     * 导出病床列表
     */
    @PreAuthorize("@ss.hasPermi('system:bed:export')")
    @Log(title = "病床", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bed bed)
    {
        List<Bed> list = bedService.selectBedList(bed);
        ExcelUtil<Bed> util = new ExcelUtil<Bed>(Bed.class);
        util.exportExcel(response, list, "病床数据");
    }

    /**
     * 获取病床详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bed:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bedService.selectBedById(id));
    }

    /**
     * 新增病床
     */
    @PreAuthorize("@ss.hasPermi('system:bed:add')")
    @Log(title = "病床", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bed bed)
    {
        return toAjax(bedService.insertBed(bed));
    }

    /**
     * 修改病床
     */
    @PreAuthorize("@ss.hasPermi('system:bed:edit')")
    @Log(title = "病床", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bed bed)
    {
        return toAjax(bedService.updateBed(bed));
    }

    /**
     * 删除病床
     */
    @PreAuthorize("@ss.hasPermi('system:bed:remove')")
    @Log(title = "病床", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bedService.deleteBedByIds(ids));
    }
}
